import java.awt.GridLayout;
import java.io.IOException;
import java.net.UnknownHostException;

import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;

/*
 * Work in progress.
 * 
 */

public class client {
	private static clientNetworkHandler net;
	private static clientGUI gui;
	
	public client() throws UnknownHostException, IOException {
		String[] choices = {"Connect","Cancel"};
		JPanel panel = new JPanel();
	 	panel.setLayout(new GridLayout(2,2));
	 	JLabel label1 = new JLabel("Address: ");
	 	JLabel label2 = new JLabel("port: ");
	    JTextField field1 = new JTextField(10);
	    JTextField field2 = new JTextField(5);
	    panel.add(label1);
	    panel.add(label2);
	    panel.add(field1);
	    panel.add(field2);
		int choice = JOptionPane.showOptionDialog(
	    			null, panel, "Connect to server",
	    			JOptionPane.OK_CANCEL_OPTION,
	    			JOptionPane.INFORMATION_MESSAGE,
	    			null,choices,
					"Connect");
		if(choice == 0) {
			net = new clientNetworkHandler(field1.getText(), field2.getText());
			gui = new clientGUI(net);
		}else {
			System.exit(0);
		}
	}
	public static void main(String [] argv) throws UnknownHostException, IOException {
		//Set osx look-and-feel
		if (System.getProperty("os.name").toLowerCase().startsWith("mac os x"))
	        System.setProperty("apple.laf.useScreenMenuBar", "true");
			new client();
	}
}
